class Community < ActiveRecord::Base

	validates_presence_of :title
	validates_uniqueness_of :title
	validates_format_of :title,    :with => /\A[a-zA-Z]+\z/, :message => "только латиница"
	
	acts_as_ferret :fields => [:title, :notes]
  acts_as_taggable
	 
	has_many :posts
  has_many :memberships, :dependent => :destroy
  has_many :users, :through=>:memberships
  belongs_to :user
  has_many :logo, :as=>:assetable, :dependent=>:destroy
  belongs_to :country
  belongs_to :city 
  
  #validates_presence_of :title, :subject
  
	def rss_channel
		community_posts_url(self)
	end
	
  def to_param
  	"#{self.id}-#{self.slug}"
  end
  
  def before_save
  	self.slug = self.title.parameterize
  end
  
  def city_name
  	self.city.nil? ? @city_name : self.city.name
  end
  
  def admins
  	admin = []
  	admin << self.user 
  end
end
